#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by master on 2017/3/4


import xml.etree.ElementTree as ET

new_xml = ET.Element("namelist")

name = ET.SubElement(new_xml, "name", attrib={"enrolled": "yes"})
age = ET.SubElement(name, "age", attrib={"checked":"no"})
sex = ET.SubElement(name, "sex")

sex.text = "male"
age.text = "33"

name2 = ET.SubElement(new_xml, "name", attrib={"enrolled": "no"})
age = ET.SubElement(name2, "age")
age.text = "19"
sex.text = "female"

et = ET.ElementTree(new_xml)
et.write("testnew.xml", encoding="utf-8", xml_declaration=True)
ET.dump(new_xml)